const app = getApp()
Page({
  data: {
    videoList: [],
    scrollHeight: 0,
    currentDrawerData: {}
  },
  toPage(e) {
    app.navigateTo(e.currentTarget.dataset.link)
  },
  onLoad() {
    this.getVideoList()
  },
  getVideoList() {
    app.axios('device', {
      op: 'ajaxDevReclogList',
      limit: 25
    }).then(res => {
      if (res.code && res.lists.length > 1) {

        this.setData({
          videoList: this.reformData(res.lists)
        })
      }
    })
  },
  reformData(source) {
    const newVideoList = source.map(item => {
      // 解析cams字段生成list数组
      const list = item.cams.split(',').map(cam => {
        const [channel, days] = cam.split('_'); // 拆解通道编号和录像天数
        return { channel, days: parseInt(days, 10) }; // 确保days是数字类型
      });

      return {
        id: item.id,
        title: item.rname,
        days: item.lxcu, // 原days字段
        list: list // 新增结构化list
      };
    });
    return newVideoList;
  },
  viewMore(e) {
    const targetId = e.currentTarget.dataset.id // 先提取 ID
    const infoItem = this.data.videoList.find(item => item.id === targetId)
    this.setData({
      currentDrawerData: infoItem
    })
    const drawer = this.selectComponent('#v-drawer')
    drawer.toggleDrawer()
  }
})